# -*- coding: utf-8 -*-
# @Time    : 2020/3/14 上午10:50
# @Author  : lilong


from abc import ABCMeta, abstractmethod


# ==============================
# 代码框架
# ==============================
class Command(metaclass=ABCMeta):
    """命令的抽象类"""

    @abstractmethod
    def execute(self):
        pass


class Receiver:
    """命令的接收者"""

    def doSomething(self):
        print("do something...")


class CommandImpl(Command):
    """命令的具体实现类"""

    def __init__(self, receiver):
        self.__receiver = receiver

    def execute(self):
        self.__receiver.doSomething()


class Invoker:
    """调度者"""

    def __init__(self):
        self.__command = None

    def setCommand(self, command):
        self.__command = command

    def action(self):
        if self.__command is not None:
            self.__command.execute()


# 基于框架的实现
# ==============================
# Test
# ==============================
def client():

    # 初始化一个调度者
    invoker = Invoker()

    # 初始化命令实现者
    command = CommandImpl(Receiver())

    # 调度者命令执行
    invoker.setCommand(command)
    invoker.action()


# testOrder()
client()
